﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VehicleFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.VehicleFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System;
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.VehicleFilter"/> type.
    /// </summary>
    public static class VehicleFilter
    {
        /// <summary>
        /// Filters the specified Vehicle collection.
        /// </summary>
        /// <param name="collection">The Vehicle collection.</param>
        /// <param name="objectToMatch">The Vehicle to match.</param>
        /// <returns>List of filtered Vehicles</returns>
        public static IQueryable<Vehicle> Filter(this IObjectSet<Vehicle> collection, Vehicle objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from vehicle in collection
                where (objectToMatch.Id == 0 || vehicle.Id == objectToMatch.Id) &&
                    (objectToMatch.Title == null || vehicle.Title.Equals(objectToMatch.Title, StringComparison.InvariantCultureIgnoreCase))
                select vehicle;
        }
    }
}